package com.sanqing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sanqing.dao.base.BaseDao;
import com.sanqing.po.ExamineBatch;
import com.sanqing.service.ExamineBatchService;
import com.sanqing.util.Page;
import com.sanqing.util.PageResult;
import com.sanqing.util.PageUtil;

@Service("examineBatchService")
@Transactional(readOnly = true)
public class ExamineBatchServiceImpl implements ExamineBatchService {

	@Resource(name = "examineBatchDao")
	private BaseDao<ExamineBatch, String> examineBatchDao;

	@Override
	public PageResult queryExamineBatchByPage(Page page, ExamineBatch examineBatch) {
		Map<String, Object> map = new HashMap<String, Object>();
		String hql = "from ExamineBatch a where 1=1";

		page = PageUtil.createPage(page.getEveryPage(), (int) examineBatchDao.countHqlResult(hql, map), page.getCurrentPage());// 根据总记录数创建分页信息
		List<ExamineBatch> list = examineBatchDao.findByPage(page, hql, map);// 通过分页信息取得试题
		PageResult result = new PageResult(page, list);// 封装分页信息和记录信息，返回给调用处
		return result;
	}

	@Override
	@Transactional(readOnly = false)
	public void add(ExamineBatch examineBatch) {
		examineBatchDao.save(examineBatch);
	}

	@Override
	public ExamineBatch getById(String id) {
		return examineBatchDao.getByKey(id);
	}

	@Override
	@Transactional(readOnly = false)
	public void edit(ExamineBatch examineBatch) {
		ExamineBatch r = examineBatchDao.getByKey(examineBatch.getId());
		BeanUtils.copyProperties(examineBatch, r, new String[] {});
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(String id) {
		examineBatchDao.delete(id);
	}

}
